﻿package com.wandian.util
{   
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;

    public class CLZSelectButton extends Object
    {
        private const UP_NO:uint = 1;
        private const OVER_NO:uint = 2;
        private const UP_YES:uint = 3;
        private const OVER_YES:uint = 4;
        private var _nRecordId:int = -1;
        private var _arrData:Array;

        public function CLZSelectButton()
        {
            return;
        }

        public function setButton(param1:Array) : void
        {
            var _loc_3:MovieClip = null;
            var _loc_4:Array = null;
            this._arrData = param1;
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = param1[_loc_2][0];
                _loc_3.mouseChildren = false;
                _loc_3.buttonMode = true;
                _loc_4 = param1[_loc_2][3].split(",");
                _loc_3.arrColor = _loc_4;
                _loc_3.txtMsg = param1[_loc_2][2];
                _loc_3.id = _loc_2;
                _loc_3.isSelected = param1[_loc_2][1];
                if (_loc_3.isSelected)
                {
                    _loc_3.gotoAndStop(this.UP_YES);
                }
                else
                {
                    _loc_3.gotoAndStop(this.UP_NO);
                }
                this.updateTxtAndColor(_loc_3);
                _loc_3.addEventListener(MouseEvent.MOUSE_OVER, this.overHandler);
                _loc_3.addEventListener(MouseEvent.MOUSE_OUT, this.outHandler);
                _loc_3.addEventListener(MouseEvent.MOUSE_DOWN, this.downHandler);
                _loc_3.addEventListener(MouseEvent.MOUSE_UP, this.upHandler);
                _loc_2 = _loc_2 + 1;
            }
            return;
        }

        private function updateTxtAndColor(param1:MovieClip, param2:int = 0) : void
        {
            if (param1.txtMsg != "")
            {
            }
            if (param1.txt != null)
            {
                param1.txt.text = param1.txtMsg;
                if (param1.arrColor != [])
                {
                    param1.txt.textColor = param1.arrColor[param2];
                }
            }
            return;
        }

        private function removeButton(param1:MovieClip) : void
        {
            param1.removeEventListener(MouseEvent.MOUSE_OVER, this.overHandler);
            param1.removeEventListener(MouseEvent.MOUSE_OUT, this.outHandler);
            param1.removeEventListener(MouseEvent.MOUSE_DOWN, this.downHandler);
            param1.removeEventListener(MouseEvent.MOUSE_UP, this.upHandler);
            return;
        }

        private function overHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as MovieClip;
            if (_loc_2.isSelected)
            {
                _loc_2.gotoAndStop(this.OVER_YES);
                this.updateTxtAndColor(_loc_2, (this.OVER_YES - 1));
            }
            else
            {
                _loc_2.gotoAndStop(this.OVER_NO);
                this.updateTxtAndColor(_loc_2, (this.OVER_NO - 1));
            }
            return;
        }

        private function outHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as MovieClip;
            if (_loc_2.isSelected)
            {
                _loc_2.gotoAndStop(this.UP_YES);
                this.updateTxtAndColor(_loc_2, (this.UP_YES - 1));
            }
            else
            {
                _loc_2.gotoAndStop(this.UP_NO);
                this.updateTxtAndColor(_loc_2, (this.UP_NO - 1));
            }
            return;
        }

        private function downHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as MovieClip;
            if (_loc_2.isSelected)
            {
                _loc_2.isSelected = false;
                _loc_2.gotoAndStop(this.UP_NO);
                this.updateTxtAndColor(_loc_2, (this.UP_NO - 1));
                this._nRecordId = -1;
            }
            else
            {
                _loc_2.isSelected = true;
                _loc_2.gotoAndStop(this.UP_YES);
                this.updateTxtAndColor(_loc_2, (this.UP_YES - 1));
                this.initUp(this._nRecordId);
                this._nRecordId = _loc_2.id;
            }
            _loc_2.dispatchEvent(new Event(Event.CHANGE));
            return;
        }

        private function upHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as MovieClip;
            if (_loc_2.isSelected)
            {
                _loc_2.gotoAndStop(this.OVER_YES);
                this.updateTxtAndColor(_loc_2, (this.OVER_YES - 1));
            }
            else
            {
                _loc_2.gotoAndStop(this.OVER_NO);
                this.updateTxtAndColor(_loc_2, (this.OVER_NO - 1));
            }
            return;
        }

        private function initUp(param1:int) : void
        {
            if (param1 < 0)
            {
                return;
            }
            var _loc_2:* = this._arrData[param1][0] as MovieClip;
            _loc_2.isSelected = false;
            _loc_2.gotoAndStop(this.UP_NO);
            this.updateTxtAndColor(_loc_2, (this.UP_NO - 1));
            return;
        }

        public function init() : void
        {
            var _loc_2:MovieClip = null;
            var _loc_1:int = 0;
            while (_loc_1 < this._arrData.length)
            {
                
                _loc_2 = this._arrData[_loc_1][0] as MovieClip;
                _loc_2.isSelected = false;
                this._nRecordId = -1;
                _loc_2.gotoAndStop(this.UP_NO);
                this.updateTxtAndColor(_loc_2, (this.UP_NO - 1));
                _loc_1 = _loc_1 + 1;
            }
            return;
        }

    }
}
